export const base64ToBlob = (base64: string, mimeType: string) => {
    const byteCharacters = atob(base64)
    const byteArrays = []
    for (let i = 0; i < byteCharacters.length; i++) {
        byteArrays.push(byteCharacters.charCodeAt(i))
    }
    return new Blob([new Uint8Array(byteArrays)], { type: mimeType })
}

export const mimeTypes = (ext: string) => {
    return {
        'png': 'image/png',
        'jpg': 'image/jpeg',
        'jpeg': 'image/jpeg',
        'gif': 'image/gif',
        'webp': 'image/webp',
        'svg': 'image/svg+xml',
        'pdf': 'application/pdf',
        'mp4': 'video/mp4',
        'mp3': 'audio/mp3',
    }[ext] || ''
}

export async function checkBlobUrlValidity(blobUrl: string) {
    try {
        const response = await fetch(blobUrl);
        return response.ok
    } catch (error) {
        return false
    }
}